#include"process.h"

#define NUM 101
#define STYPE '='
#define POINT '.'
#define SPACE ' '
const int pnum = 6;

void Process(double total,double current)
{
    //当前下载量
    double rate = (current / total) * 100;

    //更新进度条
    char bar[NUM];
    memset(bar,'\0',NUM); 
    for(int i = 0;i <(int)rate;i++)
    {
        bar[i] = STYPE;  
    }

    //下载中...模拟
    static int num = 0;
    num++;
    num %= pnum;

    char points[pnum + 1];
    memset(points,'\0',sizeof points);
    for(int i = 0;i < pnum;i++)
    {
        if(i < num) points[i] = POINT;
        else points[i] = SPACE; 
    }

    //刷新进度条
    printf("[%-100s][%.1lf%%]%s\r",bar,rate,points);
    fflush(stdout); 
    usleep(100000); 
}
